<template>
	<scroll-view class="wm">
		<block v-if="school.length > 0">
			<navigator hover-class="none" class="school" v-for="(item,i) in school" :key="item.id" :url="'/subpkg/school_detail/school_detail?schoolid='+item.id">
				<view class="logo">
					<image :src="item.logo ? logoUrl + item.logo : ''" mode="" class="school_logo"></image>	
				</view>	
				<view class="school_info">
					<view class="school_name">{{item.name}}</view>
					<view class="school_quality">学校性质：{{item.quality}} / {{item.class}}</view>
					<view class="school_grade">学校评级：{{item.grade}}</view>
					<view class="school_property">学校属性：{{item.property}}</view>
					<view class="school_address">学校地址：{{item.address}}</view>	
				</view>
			</navigator>
		</block>
		<block v-else>
			<no-data></no-data>
		</block>
		
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj:{
					pageNumber:1,
					length:10
				},
				school:[],
				isloading:false,
				total:1,
			}
		},
		onLoad(){
			this.getSchool();
		},
		computed:{
			logoUrl:function(){
				return getApp().globalData.portImageUrl +  "schoollogo/";
			}
		},
		methods: {
			async getSchool(){
				//打开节流阀
				this.isloading = true;
				const {data:res} = await uni.$http.post("Schools/getAllSchool",this.queryObj);
				this.isloading = false;
				//请求失败
				if(res.meta.status !== 1) return uni.$showMsg("获取学校数据失败");
				//请求成功
				
				this.school = [...this.school,...res.data];
				this.total = res.total;
			},
		},
		/**
		 * 学校列表上拉加载更多
		 */
		onReachBottom(){
			//根据节流阀加载数据
			if(this.isloading) return;
			//让页码值自增+1
			this.queryObj.pageNumber++
			//如果当前pageNumber大于了最大页数则不加载
			if(this.queryObj.pageNumber <= this.total){
				this.getSchool(); //请求数据
			}
		},
	}
</script>

<style lang="scss">
.school{

	background-color:#fff;
	margin-bottom:10rpx;
	display: flex;
	justify-content: left;
	align-items: center; /*垂直居中*/
	padding:20rpx;
	border-radius: 10rpx;
	.logo{
		height: 150rpx;
		width:150rpx;
		border-radius: 50%;
		overflow: hidden;
	}
	.school_logo{
		height:150rpx;
		width: 150rpx;
	}
	.school_info{
		width: 75%;
		margin-left:20rpx;
		font-size:20rpx;
		.school_name{
			font-size:30rpx;
			font-weight: bold;
		}
		.school_address{
			
		}
	}
}

</style>
